
package com.ibeeking.found.report.rest.controller.v1;

import com.ibeeking.found.report.rest.service.IBaseService;
import com.ibeeking.found.report.rest.service.IDataSourceService;
import com.ibeeking.found.report.service.common.dos.DataSourceDO;
import com.ibeeking.found.report.service.common.param.ConnectionParam;
import com.ibeeking.found.report.service.common.po.ResponseBean;
import com.ibeeking.found.report.service.common.query.DataSourcePageQuery;
import com.ibeeking.found.report.service.common.vo.DataSourceVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* @desc 数据源 controller
* @website https://gitee.com/anji-plus/gaea
* @author Raod
* @date 2021-03-18 12:09:57.728203200
**/
@RestController
@RequestMapping("/dataSource/v1")
public class DmpDataSourceController extends DmpBaseController<DataSourcePageQuery, DataSourceDO, DataSourceVO> {

    @Resource
    private IDataSourceService dataSourceServiceImpl;

    @Override
    public IBaseService<DataSourcePageQuery, DataSourceDO> getService() {
        return dataSourceServiceImpl;
    }

    @Override
    public DataSourceDO getEntity() {
        return new DataSourceDO();
    }

    @Override
    public DataSourceVO getDTO() {
        return new DataSourceVO();
    }

    /**
     * 获取所有数据源
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "获取所有数据源")
    @GetMapping("/queryAllDataSource")
    public ResponseBean queryAllDataSource() {
        return responseSuccessWithData(dataSourceServiceImpl.queryAllDataSource());
    }

    /**
     * 测试 连接
     * @param connectionParam
     * @return
     */
    @Log(logType = OperateLogTypeEnum.QUERY, describe = "测试 连接")
    @PostMapping("/testConnection")
    public ResponseBean testConnection(@Validated @RequestBody ConnectionParam connectionParam) {
        return responseSuccessWithData(dataSourceServiceImpl.testConnection(connectionParam));
    }

}
